﻿using System.Data;
using System.Text;
using System.Web;
using System.Web.SessionState;
using Yd.Domain.DAL;

namespace Yd.HttpHandler
{
    public class HandlerBase : IHttpHandler, IRequiresSessionState
    {
        public CommDAL commdal = new CommDAL();

        public string getusername(string fuid)
        {
            DataSet ds = commdal.QueryObjectAllSql("select username from yd_user where uid=" + fuid);
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0]["username"].ToString().Trim();
            }
            return fuid;
        }

        public bool IsReusable
        {
            get { return true; }
        }

        public string GetResult(string msg, string fsuccess = "false")
        {
            return "{\"success\": \"" + fsuccess + "\", \"msg\": \"" + msg.Trim() + "\"}";
        }

        public string GetResultJson(string msg, string fsuccess = "false")
        {
            return "{\"success\": \"" + fsuccess + "\", \"msg\": " + msg.Trim() + "}";
        }

        public string GetResult(string msg, int state, string fsuccess = "false")
        {
            return "{\"success\": \"" + fsuccess + "\", \"state\": \"" + state + "\", \"msg\": \"" + msg.Trim() + "\"}";
        }

        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            context.Request.ContentEncoding = Encoding.UTF8;
            context.Response.Write(Execute(context));
        }


        public virtual string Execute(HttpContext context) { return ""; }
    }
}
